package cn.wolfcode.p2p.business.service.impl;
import java.util.Date;

import cn.wolfcode.p2p.base.domain.LoginInfo;
import cn.wolfcode.p2p.business.domain.Bid;
import cn.wolfcode.p2p.business.domain.BidRequest;
import cn.wolfcode.p2p.business.mapper.BidMapper;
import cn.wolfcode.p2p.business.service.IBidService;
import cn.wolfcode.p2p.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
@Transactional
public class BidServiceImpl implements IBidService {
    @Autowired
    private BidMapper bidMapper;

    @Override
    public void save(BigDecimal amount, BidRequest br, LoginInfo loginInfo) {
        Bid bid = new Bid();
        bid.setActualRate(br.getCurrentRate());
        bid.setAvailableAmount(amount);
        bid.setBidRequestId(br.getId());
        bid.setBidUser(loginInfo);
        bid.setBidTime(new Date());
        bid.setBidRequestTitle(br.getTitle());
        bid.setBidRequestState(br.getBidRequestState());
        bidMapper.insert(bid);
    }

    @Override
    public void batchBidRequestState(Long bidRequestId, Integer bidRequestState) {
        bidMapper.batchBidRequestState(bidRequestId, bidRequestState);
    }

    @Override
    public BigDecimal getUserBid(Long bidRequestId, Long bidUserId) {
        return bidMapper.getUserBid(bidRequestId, bidUserId);
    }

    @Override
    public void batchUpdateStateByBidRequestId(Long bidRequestId, int bidRequestState) {
        bidMapper.batchUpdateStateByBidRequestId(bidRequestId ,bidRequestState);
    }
}
